//
//  LGShowDoorTableVC.m
//  ALS3.0
//
//  Created by guomianxiang on 17/3/17.
//  Copyright © 2017年 guomianxiang. All rights reserved.
//

#import "LGShowDoorTableVC.h"
#import "LGDoorInfoViewController.h"
#import "LGSearchResultVC.h"
#import "BaseViewController.h"
#import <SVProgressHUD.h>
#import "ALSHeader.h"
#import "LGDCTableHead.h"
#import "PYSearch.h"

/**
 默认sectionheader的高度
 */
#define k_headViewHeight 21

//#define weakSelf __weak typeof(LGShowDoorTableVC)weakSelf = self;


@interface LGShowDoorTableVC ()<LGDCDelegate,UISearchControllerDelegate,UITableViewDelegate,UITableViewDataSource,LGSearchResultDelegate,UIViewControllerPreviewingDelegate,LGDoorInfoViewControllerDelegate>

/**
 default
 */
@property (weak, nonatomic) IBOutlet UITableView *tableView;

/**
 搜索门是添加的高斯模糊
 */
@property (weak, nonatomic) IBOutlet UIView *visualView;

/**
 用于设置cell的数组
 */
@property (strong, nonatomic) NSArray <NSArray <LGDCCellContent *>*>* cellContentArr;

/**
 可能将会被废弃
 */
@property (strong, nonatomic) NSArray <NSArray <LGDoor *>*>*dataArr;

/**
 字母排序的sectiontitle数组
 */
@property (strong, nonatomic) NSArray <NSString *>*sectionTitleArr;

/**
 用于字母排序遮挡cell的UIImageView
 */
@property (strong, nonatomic) UIImageView *shelterImageView;


/**
 用来显示搜索结果的控制器
 */
@property (strong, nonatomic) LGSearchResultVC *resultVC;

/**
 搜索控制器
 */
@property (strong, nonatomic) UISearchController *searchC;

@property (strong, nonatomic) void(^setDoorFavoriteBlock)(LGDoor *door, NSInteger favorite);

//@property (assign, nonatomic) NSUInteger doorCount;
@property (weak, nonatomic) IBOutlet UIButton *visualBtn;

@property (strong, nonatomic) UILabel *doorCountLab;
@end


@implementation LGShowDoorTableVC

/**
 default
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNotification];
    
    [MobClick beginLogPageView:UMPageName];

    k_registerNib(self.tableView);
    
    [self.tableView setSectionIndexColor:kALSHightBlueColor];
    
    [self.tableView setSectionIndexBackgroundColor:[UIColor clearColor]];
    
    [self registerForPreviewingWithDelegate:self sourceView:self.tableView];
    
    
    __weak typeof(self)weakSelf = self;

    
    self.setDoorFavoriteBlock = ^(LGDoor *door, NSInteger favorite) {
        
        [weakSelf.tableView setEditing:NO animated:YES];
        [DCMI setDoor:door Favorite:favorite reply:^(NSIndexPath * _Nonnull changedIndexPath) {
            
            [weakSelf refreshDataScrollToTop:NO andAnimated:NO];
        }];

    };
    
    
//    self.edgesForExtendedLayout =UIRectEdgeNone;
//    self.definesPresentationContext = YES;
    [self setSearchController];

}

/**
 每次都刷新table

 @param animated default
 */
- (void)viewWillAppear:(BOOL)animated {
    [self refreshDataScrollToTop:NO andAnimated:NO];
}

- (void)viewDidDisappear:(BOOL)animated {
    [MobClick endLogPageView:UMPageName];

//    NSLog(@"----viewDidDisappear----");
//    self.navigationController.navigationBar.translucent = NO;
}

/**
 接受CMDeleteItemNotification通知，由于删除数据，并不会执行viewWillAppear:所以接受通知并刷新
 */
- (void)setNotification {
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getNotification) name:CMDeleteItemNotification object:nil];
}

/**
 收到CMDeleteItemNotification通知，刷新table
 */
- (void)getNotification {
    [self refreshDataScrollToTop:YES andAnimated:NO];
}

/**
 刷新数据并根据需求动画滚动到顶部

 @param scroll 是否滚动到顶部
 @param animated 滚动到顶部是否做动画
 */
- (void)refreshDataScrollToTop:(BOOL)scroll andAnimated:(BOOL)animated{
    
    switch (_showDoorSortState) {
        case LGShowDoorSortLetterOrderState:
        {

            self.doorCountLab.text = [NSString stringWithFormat:@"共计%lu扇门",DCMI.doors.count];


            self.dataArr = DCMI.letterOrderDoors;
            self.sectionTitleArr = [LGDCCellContent getLetterOrderListSectionDataWith:self.dataArr];

            self.cellContentArr = [LGDCCellContent transfromCellContentArrWithLetterOrderDoorsArr:self.dataArr];
            
        }
            break;
        case LGShowDoorSortUsefulFrequencyState:
        {

            self.doorCountLab.text = [NSString stringWithFormat:@"共计%lu扇门",DCMI.doors.count];

            self.cellContentArr = [LGDCCellContent transfromCellContentArrWithFrequencyDoorsArr:DCMI.usefulFrequencyOrderDoors];
        }
            break;
        case LGShowDoorDislikeState:
        {
            self.cellContentArr = [LGDCCellContent transfromCellContentArrWithDislikeDoorsArr:DCMI.usefulFrequencyOrderDoors];
            
            self.doorCountLab.text = [NSString stringWithFormat:@"共计%lu扇门不常用",self.cellContentArr[0].count];

        }
            break;
        default:
            break;
    }

    [self.tableView reloadData];
    if (scroll) {
        [self.tableView setContentOffset:CGPointMake(0, 0) animated:animated];
    }
}

/**
 设置搜索控制器
 */
- (void)setSearchController {
    
    UIView *headView = [[UIView alloc]init];
    headView.width = kScreen_W;
    headView.height = 44;
    headView.clipsToBounds = NO;
    [headView addSubview:self.doorCountLab];
    
    
    if (self.showDoorSortState == LGShowDoorDislikeState) {
        
        headView.height = 0;

        self.tableView.tableHeaderView = headView;

        return;
    }
    
    UIStoryboard *doorSB = [UIStoryboard storyboardWithName:@"DoorController" bundle:[NSBundle mainBundle]];
    
    self.resultVC = [doorSB instantiateViewControllerWithIdentifier:NSStringFromClass([LGSearchResultVC class])];
    
    self.resultVC.delegate = self;
    
//    switch (_showDoorSortState) {
//        case LGShowDoorDislikeState:
//            _resultVC.searchType = LGSearchDislickType;
//            break;
//        default:
//            _resultVC.searchType = LGSearchAllDoorType;
//            break;
//    }
    
    self.searchC = [[UISearchController alloc]initWithSearchResultsController:self.self.resultVC];
    self.searchC.dimsBackgroundDuringPresentation = NO;
    self.searchC.definesPresentationContext = NO;
    
    
    self.searchC.searchResultsUpdater = self.resultVC;
    self.searchC.delegate = self;
    
    self.searchC.searchBar.searchBarStyle = UISearchBarStyleMinimal;
    UITextField *searchField = [self.searchC.searchBar valueForKey:@"searchField"];
    searchField.textColor = [UIColor whiteColor];
    self.searchC.searchBar.tintColor = kALSHightBlueColor;
    
    [headView addSubview:self.searchC.searchBar];
    
    self.tableView.tableHeaderView = headView;

    
}

#pragma mark - LGSearchResultDelegate

/**
 LGSearchResultDelegate方法

 @param door 被点击的door
 */
- (void)didSelectDoor:(LGDoor *)door {
    
//    [self.searchC dismissViewControllerAnimated:NO completion:nil];
//    self.searchC.searchBar.showsCancelButton = NO;
//    self.searchC.searchBar.text = nil;
    
    [self performSegueWithIdentifier:@"showDoorTVCToDoorInfoTVC" sender:door];
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        
//        [self willDismissSearchController:self.searchC];
//        [self didDismissSearchController:self.searchC];
//    });
    
}

#pragma mark - UIViewControllerPreviewingDelegate
- (LGDCBaseCell *)searchCellWithPoint:(CGPoint)point {
    
    LGDCBaseCell *cell = nil;
    for (UIView *view in self.tableView.subviews) {
        NSString *class = [NSString stringWithFormat:@"%@",view.class];
        if (![class isEqualToString:@"UITableViewWrapperView"]) continue;
        for (UIView *tempView in view.subviews) {
            if ([tempView isKindOfClass:[LGDCBaseCell class]] && CGRectContainsPoint(tempView.frame, point)) {
                cell = (LGDCBaseCell *)tempView;
                break;
            }
        }
        break;
    }
    return cell;
}

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
    
    LGDCBaseCell *cell = [self searchCellWithPoint:location];
    
    if (cell.content.door == nil) {
        return nil;
    }
    
    previewingContext.sourceRect = cell.frame;
    
    UIStoryboard *DCSB = [UIStoryboard storyboardWithName:@"DoorController" bundle:nil];
    
    LGDoorInfoViewController *doorInfoVC = [DCSB instantiateViewControllerWithIdentifier:NSStringFromClass([LGDoorInfoViewController class])];
    doorInfoVC.delegate = self;
    doorInfoVC.door = cell.content.door;
    
    return doorInfoVC;
}

- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
    
    [self.navigationController pushViewController:viewControllerToCommit animated:YES];
 
}

#pragma mark - LGDoorInfoViewControllerDelegate
- (void)doorInfoVCCommitActionType:(DoorInfoActionType)actionType withDoor:(LGDoor *)door {
    
    [self.view endEditing:YES];
    
    __weak typeof(self)weakSelf = self;
    
    switch (actionType) {
        case DoorInfoActionTypeSetFavorite:
        {
            self.setDoorFavoriteBlock(door, 1);
        }
            break;
        case DoorInfoActionTypeSetDislike:
        {
            self.setDoorFavoriteBlock(door, -1);
        }
            break;
        case DoorInfoActionTypeOpenDoor:
        {
            
            [DCMI openDoor:door reply:^(BOOL success, NSError * _Nullable error) {
                if (success) {
                    [SVProgressHUD showSuccessWithStatus:[NSString stringWithFormat:@"%@:开门成功",door.doorName]];
                    //关闭提示框
                    [weakSelf closeHint];
                }else {
                    [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"%@:开门失败",door.doorName]];
                    [weakSelf closeHint];
                }
                
            }];
        }
            break;
        default:
            break;
    }
}

- (void)closeHint{
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [SVProgressHUD dismiss];
            
        });
    });
    
    
}


#pragma mark - UISearchControllerDelegate
- (IBAction)visualBtnClick:(UIButton *)sender {
    [self.searchC.searchBar resignFirstResponder];
}

/**
 UISearchControllerDelegate

 @param searchController default
 */
- (void)presentSearchController:(UISearchController *)searchController {
    self.visualView.hidden = NO;
//    self.tableView.backgroundColor = kGrayColor(237);
    
}

/**
 UISearchControllerDelegate

 @param searchController default
 */
- (void)willPresentSearchController:(UISearchController *)searchController {
    

//    UISearchBar *searchBar = searchController.searchBar;
//    
//    CGFloat value = 0.95;
//    searchBar.barTintColor = [UIColor colorWithRed:value green:value blue:value alpha:1];
//    
//    UIButton *cancelbtn = [searchBar valueForKey:@"cancelButton"];
//    [cancelbtn setTitleColor:kALSHightBlueColor forState:(UIControlStateNormal)];
//    [cancelbtn setTitleColor:kALSHightBlueColor forState:(UIControlStateHighlighted)];
//    [cancelbtn setTitleColor:kALSHightBlueColor forState:(UIControlStateSelected)];
//    
//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

/**
 UISearchControllerDelegate

 @param searchController default
 */
- (void)didPresentSearchController:(UISearchController *)searchController {
//    [searchController.searchBar sizeToFit];

}

/**
 UISearchControllerDelegate

 @param searchController default
 */
- (void)willDismissSearchController:(UISearchController *)searchController {
    
//    self.navigationController.navigationBar.translucent = YES;

//    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
//    self.tableView.backgroundColor = [UIColor clearColor];
    self.resultVC.clean = YES;

    self.visualView.hidden = YES;
    
}

/**
 UISearchControllerDelegate

 @param searchController default
 */
- (void)didDismissSearchController:(UISearchController *)searchController {

//    CGFloat value = 0.85;
//    self.searchC.searchBar.barTintColor = [UIColor colorWithRed:value green:value blue:value alpha:1];
 
}


#pragma mark - UITableViewDataSource UITableViewDelegate

/**
 UITableViewDataSource

 @param tableView default
 @return default
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.cellContentArr.count;
}

/**
 UITableViewDataSource

 @param tableView default
 @param section default
 @return default
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.cellContentArr[section].count;
}

/**
 UITableViewDataSource

 @param tableView default
 @param indexPath default
 @return default
 */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LGDCCellContent *content = self.cellContentArr[indexPath.section][indexPath.row];
    content.indexPath = indexPath;
    LGDCBaseCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(content.cellClass)];
    
    cell.content = content;
    
    if (indexPath.row == self.cellContentArr[indexPath.section].count - 1 && indexPath.section != self.cellContentArr.count - 1) {
        if ([cell isKindOfClass:[LGSketchCell class]]) {
            LGSketchCell *sketchCell = (LGSketchCell *)cell;
            sketchCell.separatorView.hidden = YES;
        }
    }
    
    return cell;
}

/**
 UITableViewDelegate

 @param tableView default
 @param indexPath default
 @return default
 */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return self.cellContentArr[indexPath.section][indexPath.row].cellHeight;
}

/**
 cell被点击 当cell对应的cellcontent.door为空时则表示当前cell为“不常用门管理助手”执行segue-@"showDoorTVCToDislickeDoorTableVC" 否则执行segue-@"showDoorTVCToDoorInfoTVC"

 @param tableView default
 @param indexPath default
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    NSLog(@"%@",self.cellContentArr);
    LGDoor *door = self.cellContentArr[indexPath.section][indexPath.row].door;
//    NSLog(@"---+++%@",door.doorName);
    if (door) {
        [self performSegueWithIdentifier:@"showDoorTVCToDoorInfoTVC" sender:door];
    }else {
        [self performSegueWithIdentifier:@"showDoorTVCToDislikeDoorTableVC" sender:nil];
    }
    
}

/**
 按字母排序返回self.sectionTitleArr 其余返回nil

 @param tableView default
 @return default
 */
- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView {
    if (_showDoorSortState == LGShowDoorSortLetterOrderState) {
        return self.sectionTitleArr;
    }
    return nil;
}

/**
 return index - 1;如果点击的index为0 则点击的时search 代码滚动到顶部

 @param tableView default
 @param title default
 @param index default
 @return default
 */
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
    if (index == 0) {
        [self.tableView setContentOffset:CGPointMake(0, 0) animated:NO];
    }
    return index - 1;
}

/**
 字母排序状态则返回 以self.sectionTitleArr[section + 1]为内容的view，其他返回nil

 @param tableView default
 @param section default
 @return default
 */
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (_showDoorSortState == LGShowDoorSortLetterOrderState) return [self tableViewHeaderViewWithTitle:self.sectionTitleArr[section + 1]];
    
    return nil;
}

/**
 根据字符串生成section header view

 @param title headerview的内容
 @return 返回uiview作为table section header view
 */
- (UIView *)tableViewHeaderViewWithTitle:(NSString *)title {
    UIView *headView = [[UIView alloc]init];
    headView.backgroundColor = [UIColor clearColor];

    headView.width = kScreen_W;
    headView.height = k_headViewHeight;
    
    UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"门九宫背景"]];
    imageView.frame = headView.bounds;
    [headView addSubview:imageView];
    
    UILabel *lable = [[UILabel alloc]init];
    lable.text = title;
    lable.font = [UIFont systemFontOfSize:15];
    lable.textColor = [UIColor whiteColor];
    [lable sizeToFit];
    lable.x += 12;
    lable.y = (headView.height - lable.height) / 2;
    [headView addSubview:lable];
    return headView;
}

/**
 字母排序返回21 其他返回0

 @param tableView default
 @param section default
 @return default
 */
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (_showDoorSortState == LGShowDoorSortLetterOrderState) return 21;
    return 0;
}

/**
 字母排序时为tableview 的section header 添加一个遮挡的UIImageView-self.shelterImageView

 @param scrollView default
 */
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (_showDoorSortState != LGShowDoorSortLetterOrderState) return;
    
    
    CGFloat offsetY = scrollView.contentOffset.y;
    
    if (offsetY < 44) {
        self.shelterImageView.hidden = YES;
    }else {
        self.shelterImageView.hidden = NO;
    }
    
    if (self.tableView.subviews.count == 1) {
        [self.tableView addSubview:self.shelterImageView];
    }
    else if (self.tableView.subviews.count > 1) {
        if (![self.tableView.subviews[1] isKindOfClass:[UIImageView class]]) {
            [self.tableView insertSubview:self.shelterImageView atIndex:1];
        }
    }
    
    UIView *view = self.tableView.subviews[1];
    view.y = offsetY;

}

/**
 当cell对应的cellcontent.door为空时  则表示是“不常用门管理助手” 返回NO

 @param tableView default
 @param indexPath default
 @return default
 */
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (self.cellContentArr[indexPath.section][indexPath.row].door == nil) return NO;
    
    return YES;
}

/**
 根据door当前的favorite 设置新的favorite

 @param tableView default
 @param indexPath default
 @return default
 */
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LGDoor *door = self.cellContentArr[indexPath.section][indexPath.row].door;
    
    NSString *favoriteTitle;
    NSString *dislikeTitle;
    
    NSInteger favorite = 0;
    NSInteger dislike = 0;
    switch (door.favorite) {
        case 0:
            favoriteTitle = @"设为常用";
            dislikeTitle = @"不常用";
            favorite = 1;
            dislike = -1;
            break;
        case -1:
            favoriteTitle = @"设为常用";
            dislikeTitle = @"取消不常用";
            favorite = 1;
            dislike = 0;
            break;
        case 1:
            favoriteTitle = @"取消常用";
            dislikeTitle = @"不常用";
            favorite = 0;
            dislike = -1;
            break;
        default:
            break;
    }
    
    __weak typeof(self) weakSelf = self;
//
//    void (^setDoorFavoriteAndMoveCell)(NSInteger, NSIndexPath *) = ^(NSInteger favorite, NSIndexPath *originalIndexPath){
//        
//        [tableView setEditing:NO animated:YES];
//        [DCMI setDoor:door Favorite:favorite reply:^(NSIndexPath * _Nonnull changedIndexPath) {
//            
//            [weakSelf refreshDataScrollToTop:NO andAnimated:NO];
//            
//        }];
//    };
    
    
    UITableViewRowAction *favoriteAction = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleNormal) title:favoriteTitle handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//        setDoorFavoriteAndMoveCell(favorite,indexPath);
        
        weakSelf.setDoorFavoriteBlock(door, favorite);
    }];
    
    UITableViewRowAction *dislikeAction = [UITableViewRowAction rowActionWithStyle:(UITableViewRowActionStyleDefault) title:dislikeTitle handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        
        weakSelf.setDoorFavoriteBlock(door, dislike);

//        setDoorFavoriteAndMoveCell(dislike,indexPath);
    }];
    
    return [NSArray arrayWithObjects:dislikeAction,favoriteAction, nil];
}

#pragma mark - Navigation

/**
 如果是跳转到LGDoorInfoViewController则为LGDoorInfoViewController的door属性赋值

 @param segue default
 @param sender default
 */
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIViewController *VC = segue.destinationViewController;
    if ([VC isKindOfClass:[LGDoorInfoViewController class]]) {
        LGDoorInfoViewController *doorInfoVC = segue.destinationViewController;
        
        doorInfoVC.door = sender;
    }
}

#pragma mark - lazy

/**
 根据背景图片为字母排序状态 生成一个遮挡cell的图片

 @return default
 */
- (UIImageView *)shelterImageView {
    if (_shelterImageView == nil) {
        //1.加载图片
        UIImage *image = [UIImage imageNamed:@"backgroung"];
        
        CGFloat height = image.size.height * k_headViewHeight / kScreen_H;
        
        CGFloat y = image.size.height * 64 / kScreen_H;
        
        //    CGRect rect = CGRectMake(0, 0, image.size.width, height);
        
        //2.生成一个跟图片相同大小图片上下文
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(image.size.width, height), NO, 0);
        
        //3.在上下文添加一个圆形裁剪区域
        //    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
        
        //    UIBezierPath *path = [UIBezierPath bezierPathWithRect:rect];
        //把路径设置成裁剪区域
        //    [path addClip];
        
        //4.把图片绘制图片上下文.
        [image drawAtPoint:CGPointMake(0, -y)];
        
        //5.生成一张图片
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        //6.关闭图片上下文.
        UIGraphicsEndImageContext();
        
        
        _shelterImageView = [[UIImageView alloc]initWithImage:newImage];
        _shelterImageView.contentMode = UIViewContentModeScaleToFill;
        //            image.clipsToBounds = YES;
        //            [image clipsToBounds];
        _shelterImageView.frame = CGRectMake(0, 0, kScreen_W, k_headViewHeight);
    }
    return _shelterImageView;
}

- (UILabel *)doorCountLab {
    if (_doorCountLab == nil) {
        _doorCountLab = [[UILabel alloc]init];
        _doorCountLab.backgroundColor = [UIColor clearColor];
        CGFloat hight = 30;
        _doorCountLab.frame = CGRectMake(0, -hight, kScreen_W, hight);
        _doorCountLab.textColor = [UIColor whiteColor];
        _doorCountLab.textAlignment = NSTextAlignmentCenter;
        _doorCountLab.font = [UIFont systemFontOfSize:14];

    }
    return _doorCountLab;
}
/**
 根据需要设置当前控制器的显示状态，具体参见LGShowDoorSortState

 @param showDoorSortState default
 */
- (void)setShowDoorSortState:(LGShowDoorSortState)showDoorSortState {
    _showDoorSortState = showDoorSortState;
    
    if (showDoorSortState != LGShowDoorDislikeState) {
        [NSUD setInteger:showDoorSortState forKey:LGShowDoorState];
    }
    self.shelterImageView.hidden = YES;
    
    [self refreshDataScrollToTop:NO andAnimated:NO];
}

/**
 移除通知 移除uisearchcontroller
 */
- (void)dealloc {
    [self.searchC.view removeFromSuperview];
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
@end

/**
 Description
 */
//@property (strong, nonatomic) UINavigationController *searchNav;


///**
// section
//
// @param tableView <#tableView description#>
// @param section <#section description#>
// @return <#return value description#>
// */
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
//    return 1;
//}
